/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Model;

/**
 *
 * @author AlexRodriguez
 */
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class ModelConection {
    
     private transient Connection con;
	private String jdbcDriver;
	private String databaseURL;
	private String user;
	private String password;



	public void connect() throws SQLException{
		if(this.isConnect())
		  throw new SQLException("Ya Esta Conectado");
		if(jdbcDriver==null)
	      throw new SQLException("No hay jdbcDriver cargado");
	    if(databaseURL==null)
	      throw new SQLException("No hay URL cargado en base de datos");
//cargar el driver
	    try{
	    	Class.forName(jdbcDriver).newInstance();
	    }catch(Exception e){
	    	throw new SQLException("La Clase"+ jdbcDriver + "No se pudo cargar");
	    }
//La conexion
	    con=DriverManager.getConnection(this.databaseURL,this.user,this.password);
	}

//Desconectar
	public void disconnect(){

    if(con!=null){
	 		try{
	 			con.close();
	 		}catch (SQLException ignore){}
	 		finally {
	 			con=null;
	 		}
	 	}
	}

	public boolean isConnect(){
	 	if(con==null)
	 	   return false;

	 	   else
	 	   return true;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getUser() {
		return user;
	}

	public void setUser(String user) {
		this.user = user;
	}

	public Connection getConexion(){
	 return con;
	}

	public String getJdbcDriver(){
	 	return jdbcDriver;
	}

	public void setJdbcDriver(String jdbcDriver){
	 	this.jdbcDriver=jdbcDriver;
	}

	public String getDatabaseURL(){
	 	return databaseURL;
	}

	public void setDatabaseURL(String databaseURL){
	 	this.databaseURL=databaseURL;
	}
    
}
